package com.sleepcamel.rest.domain.domain2Mapping;


public class DomainClassToMapping {
/*
	private Class<?> domainClass;

	public DomainClassToMapping(Class<?> domainClass) {
		this.domainClass = domainClass;
	}
	
	public Mapping getMapping(){
		Mapping mapping = new Mapping();
		mapping.setName(domainClass.getSimpleName()+"Service");
		mapping.setPath(new Path(domainClass.getSimpleName().toLowerCase()));
		
		Field[] fields = domainClass.getDeclaredFields();
		for(Field field:fields){
			if ( isVisible(domainClass, field) ){
				mapping.addChilds(generateMethodsForField(field));
			}
		}
		
		return mapping;
	}

	private Collection<RESTMethod> generateMethodsForField(Field field) {
		List<RESTMethod> methods = new ArrayList<RESTMethod>();
		String fieldName = field.getName();
		Class<?> type = field.getType();
		String titleFieldName = StringUtils.capitalize(fieldName);

		RESTMethod restMethod = new RESTMethod();
		restMethod.setType(RESTMethodType.GET);
		restMethod.setName("get"+titleFieldName);
		restMethod.setReturnType(type);
		restMethod.setPath(new Path("{id}/"+field.getName().toLowerCase()));
		methods.add(restMethod);
		
		restMethod = new RESTMethod();
		restMethod.setType(RESTMethodType.PUT);
		restMethod.setName("put"+titleFieldName);
		restMethod.setReturnType(type);
		restMethod.setPath(new Path("{id}/"+field.getName().toLowerCase()));
		methods.add(restMethod);
		
		restMethod = new RESTMethod();
		restMethod.setType(RESTMethodType.DELETE);
		restMethod.setName("delete"+titleFieldName);
		restMethod.setReturnType(void.class);
		restMethod.setPath(new Path("{id}/"+field.getName().toLowerCase()));
		
		methods.add(restMethod);
		return methods;
	}

	private boolean isVisible(Class<?> clazz, Field field) {
		if ( Modifier.isPublic(field.getModifiers()) )
			return true;
		String fieldName = field.getName();
		return classHasGetterAndSetterForField(clazz, fieldName);
	}

	private boolean classHasGetterAndSetterForField(Class<?> clazz, String fieldName) {
		Method[] methods = clazz.getMethods();
		boolean setterFound = false;
		boolean getterFound = false;
		String titleFieldName = StringUtils.capitalize(fieldName);
		
		for(Method method:methods){
			if ( Modifier.isPublic(method.getModifiers()) ){
				if ( method.getName().equals("set"+titleFieldName) )
					setterFound = true;
				
				if ( method.getName().equals("get"+titleFieldName) )
					getterFound = true;
			}
		}
		
		return setterFound && getterFound;
	}
*/
}
